//
//  PhoneViewController.swift
//  TemplateImageEditDemo
//
//  Created by liguandong on 2024/4/16.
//

import Foundation
import UIKit
import SnapKit
class PhoneViewController : UIViewController {
    var ratio1 = 0.46
    var ratio2 = 0.51
    var ratio3 = 0.75

    lazy var viewParent: UIView = {
        let v = UIView()
        v.layer.borderWidth = 2
        v.layer.borderColor = UIColor.red.cgColor
        return v
    }()
    
    lazy var bg1: UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleAspectFill
        v.image = UIImage(named: "bg1.png")!
        return v
    }()
    
    lazy var templateBack: UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleAspectFill
        v.image = UIImage(named: "templateBack.png")!
        return v
    }()
    
    lazy var templateFont: UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleAspectFill
        v.image = UIImage(named: "templateFont.png")!
        return v
    }()
    
    lazy var border: UIView = {
        let v = UIView()
        v.layer.borderWidth = 2
        v.layer.borderColor = UIColor.blue.cgColor
        return v
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let ratio = view.frame.size.width / view.frame.size.height
        debugPrint("ratio \(ratio)")
        let photoRatio = 1290.0 / 2769.0
        
        let w =  view.frame.size.width / 2
        view.addSubview(viewParent)
        viewParent.snp.makeConstraints { make in
//            make.width.equalTo(w)
//            make.height.equalTo(w / ratio1)
            make.edges.equalToSuperview()
            make.center.equalToSuperview()
        }
        viewParent.addSubview(bg1)
        viewParent.addSubview(templateBack)
        viewParent.addSubview(templateFont)
        viewParent.addSubview(border)
        bg1.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        templateBack.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        templateFont.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        border.snp.makeConstraints { make in
            make.width.equalToSuperview()
            make.height.equalTo(w / ratio3)
            make.center.equalToSuperview()
        }
    }
}
